// 主reducer
const user = window.localStorage.getItem("user");
console.log(user);
const initState = {
  // 当前登录的用户信息
  user: user ? JSON.parse(user) : null
};

export default (state = initState, action) => {
  // 登录
  if (action.type === "LOGIN") {
    // 登录 设置localStorage
    window.localStorage.setItem("user", JSON.stringify(action.user));

    return {
      ...state,
      user: action.user
    };
  }

  return state;
};
